import request from '@/common/js/request.js'
import { methods } from 'uview-ui/libs/mixin/mixin'

const mf_MyTaskUndoApi = {
  taskList: 'flow/taskList',
  suspendBusinessList: 'flow/suspendBusinessList',
  queryComment: 'flow/queryComment',
  taskExec: 'flow/taskExec',
  terminationTask: 'flow/terminationTask',
  delegate: 'flow/delegate',
  findBehindTaskExecuser: 'flow/findBehindTaskExecuser',
  backProcess: "flow/backProcess",
  getTaskdefList: "flow/getTaskdefList",
  queryLastComment: "flow/queryLastComment",
  export: "/flow/export",
}

	/**
	 * 查询当前可驳回的流程节点
	 * @param stepid        当前环节id
	 * @param processinstanceid (流程实例id, 对应act_ru_execution表PROC_INST_ID_字段)
   * @param result 结果集
	 * @return
	 */
export function getTaskdefList(stepid, processinstanceid, result) {
  return request({
    url: mf_MyTaskUndoApi.getTaskdefList,
    method: 'post',
    params: {stepid, processinstanceid}
  })
}


/*
  驳回
*/
export function backProcess(params,body) {
  return request({
    url: mf_MyTaskUndoApi.backProcess,
    method: 'post',
    params: params,
    data: body
  })
}



/*
  获取整个流程节点的执行成员
*/
export function findBehindTaskExecuser(parameter) {
  return request({
    url: mf_MyTaskUndoApi.findBehindTaskExecuser,
    method: 'post',
    params: parameter
  })
}

/**
 * 个人的待办任务
 * @param userid
 * @param pageinfo
 */
export function queryMf_MyTaskUndoList(userid, data) {
  return request({
    url: mf_MyTaskUndoApi.taskList,
    method: 'post',
    params:{userid},
    data: data,
  })
}
/**
 * 个人的挂起任务
 * @param userid
 * @param pageinfo
 */
 export function suspendBusinessList (parameter, data) {
  return request({
    url: mf_MyTaskUndoApi.suspendBusinessList,
    method: 'post',
    params: parameter,
    data: data
  })
}

/**
 * 查询流程处理记录
 * @param processinstanceid 流程定义id
 */
export function queryComment(parameter) {
  return request({
    url: mf_MyTaskUndoApi.queryComment,
    method: 'post',
    params: parameter
  })
}

/**
 * 获取进行中流程实例填写的表单数据
 * @param processinstanceid 流程定义id
 */
 export function queryLastComment(processinstanceid) {
  return request({
    url: mf_MyTaskUndoApi.queryLastComment,
    method: 'post',
    params: {processinstanceid: processinstanceid}
  })
}

/**
 * 通过/驳回待办任务
 * @param taskid 流程业务id
 * @param userid
 * @param processinstanceid 流程实例id
 * @param approved 审批结果是否同意
 * @param remark 审批意见
 */
export function taskExec(parameter, body) {
  return request({
    url: mf_MyTaskUndoApi.taskExec,
    method: 'post',
    params: parameter,
    data: body
  })
}

/**
 *终止待办任务
 * @param processinstanceid 流程实例id
 * @param deleteReason 终止原因
 */
export function terminationTask(parameter, serviceList = []) {
  return request({
    url: mf_MyTaskUndoApi.terminationTask,
    method: 'post',
    params: parameter,
    data: serviceList
  })
}

/**
 * 委托待办任务
 * @param taskid 业务id
 * @param userid 委托人的userid
 * @param entrustuserid 被委托人userid
 */
export function delegate(parameter) {
  return request({
    url: mf_MyTaskUndoApi.delegate,
    method: 'post',
    params: parameter
  })
}

/**
 * 导出待处理任务列表
 */
 export function output(userid, pageinfo) {
  let cppageinfo = JSON.parse(JSON.stringify(pageinfo))
  cppageinfo.pageSize = 2147483647
  cppageinfo.pageNumber = 1
  return request({
    url: mf_MyTaskUndoApi.export,
    method: 'post',
    params: { userid },
    data: cppageinfo,
    responseType: 'blob'
  })
}

/**
    * 通过applID获取对应的材料文件-查询全部
    * @param applyid
    * @return
 */
export function getAllMaterialByApplyId(applyid){
	return request({
		url: '/aprv_process_materials/getAllMaterialByApplyId',
		method: 'post',
		params: { applyid }
	})
}

/**
	* 查询处理页面所需参数
	* @param taskid
	* @return
 */
export function getHandleParams(taskid){
	return request({
		url: 'flow/getHandleParams',
		method: 'post',
		params: {taskid}
	})
}

/**
    * 查看行政复议相关审批表
*/
export function auditView(id){
	return request({
		url: '/apl_admre_audit/view',
		method: 'get',
		params: {id}
	})
}

/**
     * 通过applyid查询自定义材料类型
     * @param applyid
     * @return
*/
export function queryCustomerMaterialByApplyid(applyid){
	return request({
		url: '/aprv_materials_customer/queryCustomerMaterialByApplyid',
		method: 'post',
		params: {applyid}
	})
}

/**
 * 根据流程环节id查看流程表单布局设计
 */
export function viewByProcessStepId(params){
	return request({
		url: '/act_dsn_form_layout/viewByProcessStepId',
		method: 'post',
		params: params
	})
}

/**
 * 查询流程环节按钮配置列表
 * @param {*} body
 */
export function queryAct_dsn_form_stepbtnList (body) {
    return request({
        url: '/act_dsn_form_stepbtn/list',
        method: 'post',
        data: body
    })
}

/**
 * 读取流程表单数据
 * @param formid
 * @param processinstanceid
 * @param state 1 进行中流程实例表单数据, 2. 已完结的流程实例表单数据
 * @return
 */
export function loadProcessForm(formid, processinstanceid, state) {
  return request({
    url: 'flow/loadProcessForm',
    method: 'post',
    params: {
      formid,
      processinstanceid,
      state
    },
  })
}

/**
 * 查询候选用户
 * @param applyid
 * @param groupList
 * @param userList
 * @return
 */
export function queryCandidateusers(applyid, groupList, userList) {
  return request({
    url: '/sfapproveflowable/queryCandidateusers',
    method: 'post',
    params: {
      applyid
    },
    data: {
      groupList,
      userList
    }
  })
}

/**
 * 查询只要子流程的详细列表
 * @param userid
 * @param pageinfo
 */
 export function detailsBusinessList(parameter, data) {
  return request({
    url: 'flow/detailsBusinessList',
    method: 'post',
    params: parameter,
    data: data
  })
}

